package com.mall.product.service;

import com.mall.common.core.text.Convert;
import com.mall.common.utils.DateUtils;
import com.mall.product.domain.biz.ProSkuBiz;
import com.mall.product.domain.entity.ProSku;
import com.mall.product.mapper.ProSkuMapper;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * SKUService业务层处理
 *
 * @author zhonglin
 * @date 2020-05-07
 */
@Service
public class ProSkuService {

  @Autowired
  private ProSkuMapper proSkuMapper;

  /**
   * 查询SKU
   *
   * @param skuId SKUID
   *
   * @return SKU
   */
  public ProSkuBiz selectProSkuById(Long skuId) {

    return proSkuMapper.selectProSkuById(skuId);
  }

  /**
   * 查询SKU列表
   *
   * @param proSku SKU
   *
   * @return SKU
   */
  public List<ProSkuBiz> selectProSkuList(ProSku proSku) {

    return proSkuMapper.selectProSkuList(proSku);
  }

  /**
   * 新增SKU
   *
   * @param proSku SKU
   *
   * @return 结果
   */
  public int insertProSku(ProSku proSku) {

    proSku.setCreateTime(DateUtils.getNowDate());
    return proSkuMapper.insertProSku(proSku);
  }

  /**
   * 修改SKU
   *
   * @param proSku SKU
   *
   * @return 结果
   */
  public int updateProSku(ProSku proSku) {

    proSku.setUpdateTime(DateUtils.getNowDate());
    return proSkuMapper.updateProSku(proSku);
  }

  /**
   * 删除SKU对象
   *
   * @param ids 需要删除的数据ID
   *
   * @return 结果
   */
  public int deleteProSkuByIds(String ids) {

    return proSkuMapper.deleteProSkuByIds(Convert.toStrArray(ids));
  }

  /**
   * 删除SKU信息
   *
   * @param skuId SKUID
   *
   * @return 结果
   */
  public int deleteProSkuById(Long skuId) {

    return proSkuMapper.deleteProSkuById(skuId);
  }

  public int batchInsertProSku(List<ProSku> proSkus) {

    int result = 0;
    for (ProSku proSku: proSkus) {
      proSku.setCreateTime(DateUtils.getNowDate());
      result += proSkuMapper.insertProSku(proSku);
    }
    return result;
  }

}
